﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using com.codebump;

public partial class CitySquares_CitySquares : System.Web.UI.Page
{
    string _EmailServer;
    string _LoginName;
    string _LoginPassword;
    string _FromEmail;
    string _FromName;

    #region Page Navigation (Page Load, and Moving between pages of the Wizard


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.HasKeys())
            {
                if (Request.QueryString["listid"] != String.Empty)
                    Session["listid"] = Request.QueryString["listid"];
                else
                    Session["listid"] = 1;

                if (Request.QueryString["dnis"] != null)
                {
                    Session["dnis"] = Request.QueryString["dnis"];
                }
                else
                {
                    Session["dnis"] = "9999999999";
                }

                Session["servername"] = Request.QueryString["servername"];
                Session["projectname"] = Request.QueryString["projectname"];
                Session["campaignname"] = Request.QueryString["campaignname"];
                Session["agentid"] = Request.QueryString["agentid"];
                Session["agentfirst"] = Request.QueryString["agentfirst"];
                Session["agentlast"] = Request.QueryString["agentlast"];
                Session["ani"] = Request.QueryString["ani"];
                //if (Request.QueryString["leadid"] == String.Empty)
                //    Session["leadid"] = ((DataAccess)Session["App"]).FindLeadIDByPhone(Request.QueryString["ani"], Request.QueryString["dnis"]);
                //else
                Session["leadid"] = Request.QueryString["leadid"];
                Session["CInfo"] = false;
                Session["App"] = new DataAccess();

                if (Convert.ToInt32((string)Session["leadid"]) > 0)
                {
                    Session["IsOutbound"] = true;
                                      
                    LoadCustInfo(); // Pre-fill Controls with Customer Info

                    // Update CallData Table and committ
                    ((DataAccess)Session["App"]).PutCallData("IsOutbound", "Yes");
                    ((DataAccess)Session["App"]).PutCallData("LeadID", (string)Session["leadid"]);
                    ((DataAccess)Session["App"]).PutCallData("Industry", tbIndustry.Text); // This tb is filled by the LoadCustInfo() - don't want to save out to a session variable unless it is needed
                    ((DataAccess)Session["App"]).PutCallData("Notes", tbNotes.Text); // This tb is filled by the LoadCustInfo() - don't want to save out to a session variable unless it is needed
                    submitCustData(true); //btnSubmit_Click(null, null); // Run the Submit Method to Validate and Save Data to CallData Table
                    ((DataAccess)Session["App"]).CommitCallData();
                    
                    pnlOutboundOpening.Visible = true;
                    pnlInboundOpening.Visible = false;

                }
                else
                {  
                    Session["IsOutbound"] = false;
                    lblLeadID.Text = "Inbound Call";                    
                    pnlOutboundOpening.Visible = false;
                    pnlInboundOpening.Visible = true;
                    cbScheduleCallback.Visible = false;
                }

            }
            //The session variables are requested in the master page currently using the following syntax: Session["servername"] = Request.QueryString["servername"];
            //The page is loaded before the master page so if the code isn't in a control, it will currently error out.
            //((DataAccess)Session["App"]).ConnectInbound(Session["servername"].ToString(), Session["projectname"].ToString(), Session["campaignname"].ToString(), Session["dnis"].ToString(), Session["listid"].ToString());

           WebWizard.ActiveStepIndex = 0;
        }
        else
        {

        }

    }

    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }

        if (page == WebWizard.WizardSteps.IndexOf(this.MainOffer))
        {            
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }
    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {

            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        if (WebWizard.ActiveStep.Title.ToString() == "Recap")
        {
           
        }

        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {
            lblError.Text = "";
            if ((bool)Session["CInfo"]) // CInfo determine whether all required information has been entered
            {
                // Disposition as Sale
                pnlDispoConfirm.Visible = false;

                //Email Sales Info 
                EmailSet("citysquares@focusservices.com", "City Squares", "mail.focusservices.com");
                string[] EmailTo = new string[2];
                EmailTo[0] = "Brianna.Dannehl@focusservices.com";
                EmailTo[1] = "johanna.jorgenson@focusservices.com";

                string EmailSubject = "Free Trial:  Focus Services City Squares Free Trial Submitted";
                string EmailBody = "Client Information:<p>Business Name: " + tbBusiness.Text + "<br>Contact Name: " + tbFirstName.Text + " " + tbLastName.Text + 
                    "<br>City: " + tbCity.Text + "<br> ST: " + tbState.Text + "<br> Phone Number: " + tbPhone.Text + 
                    "<p> ISO Information: Focus Services <br> Sales Rep ID: " + ((DataAccess)Session["App"]).GetCallData("enterpriseagentid") + 
                    "<br> ISO Location: Ogden, UT <br>Date of Sale: " + DateTime.Today.ToShortDateString();
                if (EmailSend(EmailTo, null, EmailSubject, EmailBody, true))
                    lblError.Text = "Email Successfully Sent";
                else
                    lblError.Text = "Email Failed to Send";

                ((DataAccess)Session["App"]).PutCallData("webusercode", "01");
                ((DataAccess)Session["App"]).PutOrderItem(512, 1);
                ((DataAccess)Session["App"]).CommitOrder();
                ((DataAccess)Session["App"]).CommitCallData();
                ((DataAccess)Session["App"]).FinalizeOBLeadSales(); // The FinalizeOBLead() funtion that runs on the DispositonComplete page Load will not work since the Sales Dispositon does not exist in the dtUsercodes table?

                Response.Redirect("../DispositionComplete.aspx");
            }
            else
            {
                lblError.Text = "Customer Data Must be Saved before Dispositioning as a Sale";
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Recap);
            }
            return;
        }
        else
        {
        }

    }


    #endregion Page Navigation (Page Load, and Moving between pages of the Wizard

    protected void ddNearComputer_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddNearComputer.Text == "Yes")
        {
            pnlYesNear.Visible = true;
            pnlNoNear.Visible = false;
        }
        else
        {
            pnlYesNear.Visible = false;
            pnlNoNear.Visible = true;
        }

    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        lblError.Text = "";      
        if (validateCustomer()) //If required data is valid, check if optional data is valid. If not, set bCustValid to invalid
        {
            submitOptionalData();
            submitCustData(true);
            ((DataAccess)Session["App"]).CommitCallData();
            Session["CInfo"] = true; // If Session["cInfo"] is not True, you can not disposition as a Sale           
        }
        else
        {
            if (tbAddr.Text == "PO BOX ")
                lblError.Text += "Enter a PO BOX number <br/>";
            else
            {
                if (!(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success) || tbPhone.Text.Length != 10)
                    lblError.Text += "Enter Valid Phone Number<br/>";
                else
                    if (string.IsNullOrEmpty(tbFirstName.Text) || string.IsNullOrEmpty(tbLastName.Text))
                        lblError.Text += "Enter Contact Name<br/>";
                    else
                        lblError.Text += "Enter Valid Customer Data<br/>";

            }
        }

    }

    ///***************************
  
    //protected void btnSearchZip_Click(object sender, EventArgs e)
    //{
    //    ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);

    //}


    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;
        ddl_State.Enabled = true;
        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} +\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);
                
                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_State.Items.Add("No States Found");
                    ddl_City.Enabled = false;
                    ddl_State.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                    ddl_State.Enabled = false;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_State.Items.Add("No States Found");
                ddl_City.Enabled = false;
                ddl_State.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
            ddl_State.Items.Add("Invalid Zip");
            ddl_State.Enabled = false;
        }
    }

 


    protected void btnFAQ_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ/Objections";
        pnlWizard.Visible = false;

        if (pnlFAQ.Visible)
        {
            pnlFAQ.Visible = false;
            pnlObjections.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlFAQ.Visible = true;
            pnlObjections.Visible = true;
            btnFAQ.Text = "Return to Script";
        }
    }

    #region Validate customer info and write it to in-memory calldata table

    protected bool validateCustomer()
    {
        bool bCustValid = false;

        bCustValid = !(
            string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text) ||
            string.IsNullOrEmpty(tbBusiness.Text) ||
            string.IsNullOrEmpty(tbAddr.Text) ||
            (tbAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbCity.Text) ||
            string.IsNullOrEmpty(tbState.Text) ||
            string.IsNullOrEmpty(tbPhone.Text)) &&
            (System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success) &&
            (tbPhone.Text.Length == 10) ;
            //(ddlCity.SelectedIndex > 0);


        return bCustValid;
    }

  
    protected void submitCustData(bool bCustValid)
    {
        if (bCustValid)
        {
            ((DataAccess)Session["App"]).PutCallData("BusinessName", tbBusiness.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("address1", tbAddr.Text.Replace(",", ""));
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                ((DataAccess)Session["App"]).PutCallData("address2", tbAddr2.Text.Replace(",", ""));
            else
                ((DataAccess)Session["App"]).PutCallData("address2", "");
            ((DataAccess)Session["App"]).PutCallData("City", tbCity.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("State", tbState.Text);            
            ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", tbPhone.Text.Replace(",", ""));
            
        }
        //this else covers error checking
        else
        {
            if (tbAddr.Text == "PO BOX ")
            {
                lblError.Text += "Enter a PO BOX number <br/>";
            }
            else
            {
                if (!(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success) || tbPhone.Text.Length != 10)
                    lblError.Text += "Enter Valid Phone Number<br/>";
                else
                    if (string.IsNullOrEmpty(tbFirstName.Text) || string.IsNullOrEmpty(tbLastName.Text))
                        lblError.Text += "Enter Contact Name<br/>";
                    else
                        lblError.Text += "Enter Valid Customer Data<br/>";
                
            }
        }

    }
    protected bool submitOptionalData()
    {
        bool bOpt = true;

        //// Validate Alt Phone
        //if ((!string.IsNullOrEmpty(tbAltPhone.Text)) && ((tbAltPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbAltPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        //{
        //    lblError.Text += "Invalid Alt Phone<br/>";
        //    bOpt = false;
        //}
        //else
        //{
        //    if (!string.IsNullOrEmpty(tbAltPhone.Text))
        //        ((DataAccess)Session["App"]).PutCallData("AltPhone", tbAltPhone.Text);
        //    else
        //        ((DataAccess)Session["App"]).PutCallData("AltPhone", "");
        //}
        // Validate Email
        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
            bOpt = false;
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text);
            else
                ((DataAccess)Session["App"]).PutCallData("Email", "");
        }

        // Notes
        if (!string.IsNullOrEmpty(tbNotes.Text))
            ((DataAccess)Session["App"]).PutCallData("Notes", tbNotes.Text.Replace(",", ""));
        else
            ((DataAccess)Session["App"]).PutCallData("Notes", "");
       

        return bOpt;
    }

    public bool ValidateEmail()
    {
        if (string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("Email")) || !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text) )
            return false;
        else
            return true;
    }

    public bool ValidatePhone()
    {
        //if (string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("PrimaryPhone")) ||
        //    ((DataAccess)Session["App"]).GetCallData("PrimaryPhone").ToString().Length != 10 ||
        //    !(System.Text.RegularExpressions.Regex.Match(((DataAccess)Session["App"]).GetCallData("FirstName").ToString(), @"^[1-9]\d{2}[1-9]\d{6}$").Success))
        if (((DataAccess)Session["App"]).GetCallData("PrimaryPhone").ToString().Length == 10)
            return true;
        else
            return false;
    }
    public bool ValidateContactName()
    {
        if (string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("FirstName")) || string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("LastName")))
            return false;
        else
            return true;
    }

    #endregion Validate customer info and write it to in-memory calldata table


    protected void btnCallBack_Click(object sender, EventArgs e)
    {
        //if (!validateCustomer())//(String.IsNullOrEmpty(tbPhone.Text) || tbPhone.Text.Length != 10)
        //{
        //    //lblCallBackNoPhone.Visible = true;
        //    //ScheduleCallBack = false;
        //    lblError.Text = "Please Enter Valid Customer Info Before Scheduling a CallBack";
        //}
        //else
        //{
            if (ddlBestTime.SelectedIndex == 0 || String.IsNullOrEmpty(calBestDay.SelectedDate.ToShortDateString()))
                lblError.Text = "Please Select Date and Best Time To CallBack";
            else
            {
                if (!ValidatePhone())
                {
                    lblError.Text = "Please Enter Valid Phone Number and Submit";
                }
                else
                {
                    string BestTime = "";
                    switch (ddlBestTime.SelectedIndex)
                    {
                        case 1:
                            BestTime = "9:00:00 AM";
                            break;
                        case 2:
                            BestTime = "11:00:00 AM";
                            break;
                        case 3:
                            BestTime = "4:00:00 PM";
                            break;
                        default:
                            BestTime = "9:00:00 AM";
                            break;
                    }

                    //submitCustData(true);
                    ((DataAccess)Session["App"]).PutCallData("BestDay", calBestDay.SelectedDate.ToShortDateString()+ " " + BestTime);
                    ((DataAccess)Session["App"]).PutCallData("BestTimeOfDay", BestTime);
                    ((DataAccess)Session["App"]).PutCallData("Callback", "true");
                    if (cbDedicatedCallback.Checked)
                    {                    
                        ((DataAccess)Session["App"]).PutCallData("DedicatedCallback", "true");
                        ((DataAccess)Session["App"]).PutCallData("webusercode", "03");  //Callback Usercode
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutCallData("DedicatedCallback", "false");
                        ((DataAccess)Session["App"]).PutCallData("webusercode", "02");  //Callback Usercode

                    }
                    ((DataAccess)Session["App"]).CommitCallData();
                    ((DataAccess)Session["App"]).CallbackOBLead(calBestDay.SelectedDate.ToShortDateString() + " " + BestTime, ((DataAccess)Session["App"]).GetCallData("PrimaryPhone"), ((DataAccess)Session["App"]).GetCallData("webusercode"), ((DataAccess)Session["App"]).GetCallData("Callback"), ((DataAccess)Session["App"]).GetCallData("DedicatedCallback"), ((DataAccess)Session["App"]).GetCallData("enterpriseagentid"));
                    Response.Redirect("../DispositionComplete.aspx");

                }
        }
    }

    protected void calBestDay_SelectionChanged(object sender, EventArgs e)
    {
        //lblDate.Text = calBestDay.SelectedDate.ToString("D");
    }
    protected void ddlBestTime_SelectedIndexChanged(object sender, EventArgs e)
    {
        //lblBestTime.Text = ddlBestTime.SelectedValue.ToString();
    }


    protected void cbScheduleCallback_CheckedChanged(object sender, EventArgs e)
    {
        if (cbScheduleCallback.Checked)
            pnlCallBack.Visible = true;
        else
            pnlCallBack.Visible = false;

    }


    protected void btnSendEmail_Click(object sender, EventArgs e)
    {

        if (!ValidateEmail())//(String.IsNullOrEmpty(tbPhone.Text) || tbPhone.Text.Length != 10)
        {
            lblError.Text = "Please Enter Valid Customer Info including Email Info and Submit Before Attempting to Send Email";
        }
        else
        {
            EmailSet("citysquares@focusservices.com", "City Squares", "mail.focusservices.com");

            string[] EmailTo = new string[1];
            string[] EmailAttachments = new string[1];
            EmailTo[0] = ((DataAccess)Session["App"]).GetCallData("Email");
            EmailAttachments[0] = "D:\\WebSites\\OgdenScripts.focusservices.com\\SharedPool\\CitySquares\\PitchPowerPoint.pdf"; //"C:\\Test\\PitchPowerPoint.pdf";
            string EmailSubject = "City Squares Presentation";
            string EmailBody = "Thank you for taking a few moments to learn about City Squares free tial offer.  Attached is our presentation for you to review.";
            if (EmailSend(EmailTo, null, EmailSubject, EmailBody, false, EmailAttachments))
                lblError.Text = "Email Successfully Sent";
            else
                lblError.Text = "Email Failed to Send";

        }
    }

    #region Email Procedures
    public void EmailSet(string FromEmail, string FromName, string EmailServer, string LoginName, string LoginPassword)
    {
        _EmailServer = EmailServer;
        _LoginName = LoginName;
        _LoginPassword = LoginPassword;
        _FromEmail = FromEmail;
        _FromName = FromName;

    }

    //This is an overload in case the username and password are not requried
    public void EmailSet(string FromEmail, string FromName, string EmailServer)
    {
        _EmailServer = EmailServer;
        _FromEmail = FromEmail;
        _FromName = FromName;
    }

    public bool EmailSend(string[] _ToEmail, string[] _CCEmail, string _Subject, string _EmailBody, bool _IsBodyHtml, string[] _Attachments)
    {

        try
        {
            // setup email header
            System.Net.Mail.MailMessage _MailMessage = new System.Net.Mail.MailMessage();

            // Set the message sender
            // sets the from address for this e-mail message.
            _MailMessage.From = new System.Net.Mail.MailAddress(_FromEmail, _FromName);
            // Sets the address collection that contains the recipients of this e-mail message.
            int counter = 0;
            foreach (string Recipients in _ToEmail)
            {
                _MailMessage.To.Add(new System.Net.Mail.MailAddress(_ToEmail[counter]));
                counter++;
            }

            counter = 0;
            if (_CCEmail != null && _CCEmail.Length > 0)
            {
                foreach (string CCRecipients in _CCEmail)
                {
                    _MailMessage.CC.Add(new System.Net.Mail.MailAddress(_CCEmail[counter]));
                    counter++;
                }
            }

            // sets the message subject.
            _MailMessage.Subject = _Subject;
            // sets the message body.
            _MailMessage.Body = _EmailBody;
            // sets a value indicating whether the mail message body is in Html.
            // if this is false then ContentType of the Body content is "text/plain".
            _MailMessage.IsBodyHtml = _IsBodyHtml;

            // add all the file attachments if we have any
            if (_Attachments != null && _Attachments.Length > 0)
                foreach (string _Attachment in _Attachments)
                    _MailMessage.Attachments.Add(new System.Net.Mail.Attachment(_Attachment));

            // SmtpClient Class Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
            System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail.SmtpClient(_EmailServer);

            //Specifies how email messages are delivered. Here Email is sent through the network to an SMTP server.
            _SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

            // Some SMTP server will require that you first authenticate against the server.
            // Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
            System.Net.NetworkCredential _NetworkCredential = new System.Net.NetworkCredential(_LoginName, _LoginPassword);
            _SmtpClient.UseDefaultCredentials = false;
            _SmtpClient.Credentials = _NetworkCredential;

            //Let's send it
            _SmtpClient.Send(_MailMessage);

            // Do cleanup
            _MailMessage.Dispose();
            _SmtpClient = null;
        }
        catch
        {
            return false;
        }
        return true;
    }

    public bool EmailSend(string[] _ToEmail, string[] _CCEmail, string _Subject, string _EmailBody, bool _IsBodyHtml)
    {
        try
        {
            // setup email header
            System.Net.Mail.MailMessage _MailMessage = new System.Net.Mail.MailMessage();

            // Set the message sender
            // sets the from address for this e-mail message.
            _MailMessage.From = new System.Net.Mail.MailAddress(_FromEmail, _FromName);
            // Sets the address collection that contains the recipients of this e-mail message.
            int counter = 0;
            foreach (string Recipients in _ToEmail)
            {
                _MailMessage.To.Add(new System.Net.Mail.MailAddress(_ToEmail[counter]));
                counter++;
            }

            counter = 0;
            if (_CCEmail != null && _CCEmail.Length > 0)
            {
                foreach (string CCRecipients in _CCEmail)
                {
                    _MailMessage.CC.Add(new System.Net.Mail.MailAddress(_CCEmail[counter]));
                    counter++;
                }
            }

            // sets the message subject.
            _MailMessage.Subject = _Subject;
            // sets the message body.
            _MailMessage.Body = _EmailBody;
            // sets a value indicating whether the mail message body is in Html.
            // if this is false then ContentType of the Body content is "text/plain".
            _MailMessage.IsBodyHtml = _IsBodyHtml;


            // SmtpClient Class Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
            System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail.SmtpClient(_EmailServer);

            //Specifies how email messages are delivered. Here Email is sent through the network to an SMTP server.
            _SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

            // Some SMTP server will require that you first authenticate against the server.
            // Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
            System.Net.NetworkCredential _NetworkCredential = new System.Net.NetworkCredential(_LoginName, _LoginPassword);
            _SmtpClient.UseDefaultCredentials = false;
            _SmtpClient.Credentials = _NetworkCredential;

            //Let's send it
            _SmtpClient.Send(_MailMessage);

            // Do cleanup
            _MailMessage.Dispose();
            _SmtpClient = null;
        }
        catch
        {
            return false;
        }
        return true;
    }

    #endregion Email Procedures

    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    // Checks for previously entered CallData based on the LeadID, if none, then loads Info from Leads Table
    protected void LoadCustInfo()
    {

        lblLeadID.Text += Convert.ToString(Session["leadid"]);        
        tbPhone.Text = Session["ani"].ToString(); //((DataAccess)Session["App"]).OBGetLeadData("PrimaryPhone").ToString();  Use Query String ANI (number dialed by OB Dialer) in case PHone has been updated on previous calls                    
        
        if (((DataAccess)Session["App"]).FillPreviousCallData(Convert.ToString(Session["leadid"])))
        {
            tbBusiness.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("BusinessName").ToString();
            tbAddr.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("Address1").ToString();
            tbCity.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("City").ToString();
            tbState.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("State").ToString();
            tbIndustry.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("Industry").ToString();
            tbFirstName.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("FirstName").ToString();
            tbLastName.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("LastName").ToString();
            tbEmail.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("Email").ToString();
            tbNotes.Text = ((DataAccess)Session["App"]).OBGetPreviousCallData("Notes").ToString();
        }
        else
        {
            ((DataAccess)Session["App"]).FillLeadData(Convert.ToString(Session["leadid"]));
            tbBusiness.Text = ((DataAccess)Session["App"]).OBGetLeadData("BusinessName").ToString();
            tbAddr.Text = ((DataAccess)Session["App"]).OBGetLeadData("Address1").ToString();
            tbCity.Text = ((DataAccess)Session["App"]).OBGetLeadData("City").ToString();
            tbState.Text = ((DataAccess)Session["App"]).OBGetLeadData("State").ToString();
            tbIndustry.Text = ((DataAccess)Session["App"]).OBGetLeadData("Industry").ToString();
        }       

    }

    protected void tbCallbackTimeSpecific_TextChanged(object sender, EventArgs e)
    {

    }
}
